package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.YunjiayiAddress;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface YunjiayiAddressMapper {
    @Delete({
        "delete from yunjiayi_address",
        "where address_id = #{addressId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer addressId);

    @Insert({
        "insert into yunjiayi_address (address_id, address, ",
        "aduserId, defaultAddress, ",
        "telephone, note)",
        "values (#{addressId,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, ",
        "#{aduserid,jdbcType=INTEGER}, #{defaultaddress,jdbcType=BIT}, ",
        "#{telephone,jdbcType=VARCHAR}, #{note,jdbcType=VARCHAR})"
    })
    int insert(YunjiayiAddress record);

    @Select({
        "select",
        "address_id, address, aduserId, defaultAddress, telephone, note",
        "from yunjiayi_address",
        "where address_id = #{addressId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="address_id", property="addressId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="aduserId", property="aduserid", jdbcType=JdbcType.INTEGER),
        @Result(column="defaultAddress", property="defaultaddress", jdbcType=JdbcType.BIT),
        @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
        @Result(column="note", property="note", jdbcType=JdbcType.VARCHAR)
    })
    YunjiayiAddress selectByPrimaryKey(Integer addressId);

    @Select({
        "select",
        "address_id, address, aduserId, defaultAddress, telephone, note",
        "from yunjiayi_address"
    })
    @Results(id = "addressMap",value = {
        @Result(column="address_id", property="addressId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="aduserId", property="aduserid", jdbcType=JdbcType.INTEGER),
        @Result(column="defaultAddress", property="defaultaddress", jdbcType=JdbcType.BIT),
        @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
        @Result(column="note", property="note", jdbcType=JdbcType.VARCHAR)
    })
    List<YunjiayiAddress> selectAll();

    /*通过用户id查询address*/
    @Select("select * from yunjiayi_address where aduserId=#{uId}")
    @ResultMap("addressMap")
    List<YunjiayiAddress> selectAddressByuId(@Param("uId")Integer uId);

    @Update({
        "update yunjiayi_address",
        "set address = #{address,jdbcType=VARCHAR},",
          "aduserId = #{aduserid,jdbcType=INTEGER},",
          "defaultAddress = #{defaultaddress,jdbcType=BIT},",
          "telephone = #{telephone,jdbcType=VARCHAR},",
          "note = #{note,jdbcType=VARCHAR}",
        "where address_id = #{addressId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(YunjiayiAddress record);
}